<?php
header ( "Content-Type: text/html; charset=utf-8" );
require ("config.inc.php");
require_once (COMM_PATH . "upload.php");

$baseDir = INCLUDE_PATH . "upload";
$baseTxt_Dir =  INCLUDE_PATH . "TXT_FILE";
$extention_list = "jpg|doc|zip|rar|gif";
$fileSize = 1;
if ($_SERVER ["REQUEST_METHOD"] == 'POST') {
	if ($_FILES ["file"] ["error"] > 0) {
		echo "Return Code: " . $_FILES ["file"] ["error"] . "<br />";
	} else {
		$up = new upload_file ( $_FILES ["file"] ["tmp_name"], $_FILES ["file"] ["name"], $_FILES ["file"] ["size"], $baseDir, $extention_list, $fileSize );
		//$up->set_is_default_filename ( true ); //用原始文件名
		//$up->set_have_subdirectory ( true, "12" ); //创建子目录 目录名12
		$up->upload ();
		echo $up->file_path."---";
		echo $up->file_last_name." <br/>";
		
		if(file_exists($up->file_path))
			{
			$zip=zip_open(realpath($up->file_path));
			
			    if (is_resource($zip)) {
			        while ($zip_entry = zip_read($zip)) {
			        	$txtName = zip_entry_name($zip_entry);
//			            echo "Name:               " . zip_entry_name($zip_entry) . " <br/>";
//			            echo "Actual Filesize:    " . zip_entry_filesize($zip_entry) . " <br/>";
//			            echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry) . " <br/>";
//			            echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . " <br/>";
			
			            if (zip_entry_open($zip, $zip_entry, "r")) {
//			                echo "File Contents: ";
			                $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
//			                echo "$buf ";
							$buf = mb_convert_encoding($buf, "UTF-8", "UCS-2");//转化编码
							$buf = str_replace("﹁", "「", $buf);
							$buf = str_replace("︽", "《", $buf);
							$buf = str_replace("︾", "》", $buf);
							$buf = str_replace("﹂", "」", $buf);
							$buf = str_replace("︵", "（", $buf);
							$buf = str_replace("︶", "）", $buf);
							$buf = str_replace("﹃", "『", $buf);
							$buf = str_replace("﹄", "』", $buf);
							
							
							file_put_contents($baseTxt_Dir."/".$txtName, $buf);
			
			                zip_entry_close($zip_entry);
			            }
//			            echo " <br/>";
			
			        }
			        zip_close($zip);
			    }else{
			        echo "can not open the file: test.zip";   
			    }
			}else{
			    echo "can not find the file: test.zip";
			}
		
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>阅读</title>
</head>

<body>

<form action="testFile.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label> <input type="file" name="file"
	id="file" /> <br />
<input type="submit" name="submit" value="Submit" /></form>
</body>
</html>